﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cricket.LinqModel;
using Cricket.LinqData;


public partial class ClearData : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    
    MatchSchedule matchSchedule;
    List<MatchSchedule> matchSchedules;
    
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bindMatch();
        }
    }

    private void bindMatch()
    {
        matchSchedule = new MatchSchedule(_dataObject);
        List<GetAllMatchesForDeleteResult> lst = new List<GetAllMatchesForDeleteResult>();
        lst = matchSchedule.GetAllMatchesForDelete();
        if (lst.Count > 0)
        {
            chkMatch.DataSource = lst;
            chkMatch.DataTextField = "Match";
            chkMatch.DataValueField = "Id";
            chkMatch.DataBind();
            chkMatch.Visible = true;
        }
        else
        {
            chkMatch.Visible = false;
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        matchSchedule = new MatchSchedule(_dataObject);
        for (int i = 0; i < chkMatch.Items.Count; i++)
        {
            if (chkMatch.Items[i].Selected)
            {
                matchSchedule.Id = Convert.ToInt32(chkMatch.Items[i].Value);
                _dataObject.DeleteData(matchSchedule.Id);
            }            

        }
        Response.Redirect("ClearData.aspx");
    }
}